<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/picker.css" />
		<link rel="stylesheet" href="css/poppicker.css" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" href="css/member.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav public-color">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">编辑地址</h1>
			<lable class="mui-pull-right edit" id="btn" style='color: #fff;'>保存</lable>
		</header>
		<div class="mui-content address_content" id="update_div">
			<form class="mui-input-group address_group">
				<div class="mui-input-row ">
					<label>收货人</label>
					<input id="shouhuoren" type="text" class="mui-input-group" placeholder="无敌小能手">
				</div>
				<div class="mui-input-row">
					<label>联系电话</label>
					<input id="my_phone" type="text" class="mui-input-group" placeholder="18973566285">
				</div>
				<div class="mui-input-row">
					<label>所在地区</label>
					<input type="text" id="district" readonly="readonly" class="mui-input-group" placeholder="湖南省 郴州市 北湖区">
				</div>
				<div class="mui-input-row">
					<label>详细地址</label>
					<input id="my_address" type="text" class="mui-input-group" placeholder="青年大道五岭广场天一华府C座2701">
				</div>
			</form>
			<div class="address_mor clearfix">
				<span>设为默认</span>
				<div id="isdefault" class="mui-switch mui-switch-mini" data-mystate="1">
					<div id="isdefault2" class="mui-switch-handle"></div>
					<input type="hidden" id="default" value="1">
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/castapp.js"></script>
		<script src="js/picker.js"></script>
		<script src="js/poppicker.js"></script>
		<script src="js/city.data-3.js"></script>
		<script src="js/app.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/jbase64.js"></script>
		<script type="text/javascript" src="js/layer/layer.min.js"></script>
		<script>
			//显示需要编辑得内容
			$(function() {
				getsjFoot();
				$.ajax({
					//type: 'post',
					url: APP.api_url + 'member/update_AddressList',
					data: {
						token: get_token(),
						id: getUrlParam("id"),
						uid: getUid()
					},
					success: function(data) {
						if(data.code == 200) {
							var json = data.data;
							$("#shouhuoren").val(json.realname);
							$("#my_phone").val(json.mobile);
							$('#district').val(json.province + ',' + json.city + ',' + json.district);
							$("#my_address").val(json.address);
							if(json.isdefault == 2) {
								//transition-duration: 0.2s; transform: translate(16px, 0px);
								$("#isdefault2").css("transition-duration", "0.2s");
								$("#isdefault2").css("transform", "translate(16px, 0px)");
								$("#isdefault").addClass("mui-active");
								$("#isdefault").data("mystate", 2);
							}
						} else {
							console.log(data.msg);
						}
					}
				})
			});
		</script>
		<script>
			ca.init();
			var btn = ca.id('btn');
			var input = ca.tagName('input');
			var dis = ca.id('district');
			dis.addEventListener('tap', function() {
				//三级组合
				castapp.combinationSelect(3, cityData3, function(arr) {
					dis.value = arr;
				});
			})
			btn.addEventListener('tap', function() {
				var username = input['0'].value;
				var tel = input['1'].value;
				var district = input['2'].value;
				var address = input['3'].value;
				if(username == "") {
					ca.prompt('收货人姓名不能为空');
					return;
				}
				if(tel == "") {
					ca.prompt('手机号码不能为空');
					return;
				}
				if(district == "") {
					ca.prompt('地区不能为空');
					return;
				}
				if(address == "") {
					ca.prompt('详细地址不能为空');
					return;
				}
				btn.disabled = true;
				var disarr = district.split(',');
				//默认状态
				var isdefault = $("#isdefault").data("mystate");
				//写入数据库
				$.ajax({
					//请求的url
					url: APP.api_url + 'member/update_address',
					//请求的过程中传递过去的参数 json
					data: {
						token: get_token(),
						id: getUrlParam('id'),
						uid: getUid(),
						realname: username,
						mobile: tel,
						province: disarr[0],
						city: disarr[1],
						district: disarr[2],
						address: address,
						isdefault: isdefault
					},
					//成功了的回调，并且带有返回值
					success: function(data) {
						if(data.code == 200) {
							url_jump(data, "address");
						} else {
							console.log(data.msg);
						}
					}
				})
			});
		</script>
		<script>
			$("#isdefault").click(function() {
				var my = $("#isdefault").data("mystate");
				var my_state = 1;
				if(parseInt(my) == 1) {
					$("#isdefault").data("mystate", 2);
				} else {
					$("#isdefault").data("mystate", 1);
				}
			})
		</script>
	</body>

</html>